Recette n 50 Grer des buckets avec Amazon S3
Page 148


// On initialise le client S3
s3Client = new AmazonS3Client(new BasicAWSCredentials(ACCESS_KEY_ID, SECRET_KEY));
s3Client.setEndpoint("s3-eu-west-1.amazonaws.com");

private class CreateBucketTask extends AsyncTask<String, Void, Void>
{
   @Override
   protected Void doInBackground(String... bucketsNames)
   {
      try
      {
         // On cr les buckets directement dans notre rgion
         // d'utilisation (par dfaut Region.US_Standard)
         for(int i = 0; i < bucketsNames.length; i++)
         {
            s3Client.createBucket(bucketsNames[i], Region.EU_Ireland);
         }
      }
      catch (Exception e)
      {
         // Exceptions possibles : AmazonClientException et AmazonServiceException
         Log.d("AWS", "Erreur creation : " + e.toString());
      }

      return null;}
}










private class DeleteBucketTask extends AsyncTask<String, Void, Void>
{
   @Override
   protected Void doInBackground(String... bucketsNames)
   {
      try
      {
         // On supprime les buckets
         for(int i = 0; i < bucketsNames.length; i++)
         {
            s3Client.deleteBucket(bucketsNames[i]);
         }
      }
      catch (Exception e)
      {
         // Exceptions possibles : AmazonClientException et AmazonServiceException
         Log.d("AWS", "Erreur suppression : " + e.toString());
      }

      return null;
   }
}
